package com.huan.flowsun;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowCountReducer extends Reducer<Text,FlowBean,Text,FlowBean> {

    FlowBean v = new FlowBean();
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
        //TODO 定义累加变量
        long sum_unFlow = 0;
        long sum_downFlow = 0;
       // TODO  遍历所用bean，将其中的上行流量，下行流量分别累加
        for (FlowBean value : values) {
            sum_unFlow += value.getUpFlow();
            sum_downFlow += value.getDownFlow();
        }

        //TODO 封装对象
        v.set( sum_unFlow,sum_downFlow );

        //TODO 写出
        context.write( key,v );
    }

}
